package com.bishe.tax.controller.sys;

import com.bishe.tax.entity.SysUser;
import com.bishe.tax.entity.ToDoTask;
import com.bishe.tax.service.ToDoaskService;
import com.bishe.tax.utils.AjaxResult;
import com.bishe.tax.utils.TableDataInfo;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("toDoTask")
public class ToDoTaskController {

    @Autowired
    private ToDoaskService taskService;

    @GetMapping("list/{type}")
    public String toList(@PathVariable("type") String type, ModelMap mmp) {
        mmp.put("type", type);
        return "toDoTask/list";
    }

    @PostMapping("list/{type}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("type") String type, HttpSession session) {
        SysUser user = (SysUser) session.getAttribute("sysUser");
        List<ToDoTask> ls = taskService.seletTaskList(type, user.getUserId());
        return TableDataInfo.returnDataTable(new PageInfo<>(ls).getTotal(), ls);
    }

    @PostMapping("complete")
    @ResponseBody
    public AjaxResult complete(@RequestParam("taskId") String taskId, @RequestParam("flag") Boolean flag, HttpSession session) {
        taskService.doComplete(taskId, flag);
        return AjaxResult.success("操作成功！");
    }

}
